const state={
  user:JSON.parse(sessionStorage.getItem('$user')) || {},
}

const getters={
  getUser:state=>{
    return state.user;
  }
}

const actions={
  setUser({commit},item){
    commit('setUser',item)
  },
}

const mutations={
  setUser(state, item) {
    //信息存入state
  state.user=item;
  //信息存入sessionStorage
  sessionStorage.setItem('$user',JSON.stringify(state.user))
  },
  //注销登录
  clearUser(state){
    state.user={},
      sessionStorage.setItem('$user',JSON.stringify(state.user))
  },
}

export default {
  state,
  getters,
  actions,
  mutations
}
